package com.example.gcjjhd.agriculture.service;

import com.example.gcjjhd.agriculture.entity.Alert;
import com.example.gcjjhd.agriculture.repository.AlertRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class AlertService {
    @Autowired
    private AlertRepository alertRepository;

    public List<Alert> getAllActiveAlerts() {
        return alertRepository.findByStatus("active");
    }

    public Alert acknowledgeAlert(Integer alertId) {
        Alert alert = alertRepository.findById(alertId).orElse(null);
        if (alert != null) {
            alert.setStatus("acknowledged");
            return alertRepository.save(alert);
        }
        return null;
    }
}